home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-23 | 3.9 KB | 136 lines |
- /*
- * QuickTime for Java SDK Sample Code
-
- Usage subject to restrictions in SDK License Agreement
- * Copyright: © 1996-1999 Apple Computer, Inc.
-
- */
- import java.awt.*;
- import java.awt.event.*;
- import java.applet.*;
- import java.io.IOException;
-
-
- import quicktime.*;
- import quicktime.io.*;
- import quicktime.std.*;
- import quicktime.std.movies.*;
- import quicktime.app.players.*;
- import quicktime.app.display.*;
-
-
- public class FileMenu {
- PlayMovie myPlayMovie;
-
- public FileMenu (PlayMovie src) {
- this.myPlayMovie = src;
-
- // make the menu bar up
- MenuBar menuBar = new MenuBar();
- Menu fileMenu = new Menu ("File");
-
- MenuItem openMenuItem = new MenuItem ("Open...");
- MenuItem openURLMenuItem = new MenuItem("Open URL...");
- MenuItem presentMovieMenuItem = new MenuItem ("Present Movie");
- MenuItem quitMenuItem = new MenuItem("Quit");
-
- fileMenu.add(openMenuItem);
- fileMenu.add(openURLMenuItem);
- fileMenu.addSeparator();
- fileMenu.add(presentMovieMenuItem);
- fileMenu.addSeparator();
- fileMenu.add(quitMenuItem);
-
- menuBar.add (fileMenu);
- myPlayMovie.setMenuBar (menuBar);
-
- openURLMenuItem.addActionListener (new ActionListener () {
- public void actionPerformed(ActionEvent event) {
- myPlayMovie.stopPlayer();
-
- // this will set the new movie in its action method if OK is chosen
- Open_URL d = new Open_URL (myPlayMovie);
- d.pack();
- d.show();
- }
- });
- openMenuItem.addActionListener (new ActionListener () {
- public void actionPerformed(ActionEvent event) {
- myPlayMovie.stopPlayer();
-
- // creat a movie through the file-open dialog of QT
- try {
- QTFile qtf = QTFile.standardGetFilePreview(QTFile.kStandardQTFileTypes);
- myPlayMovie.createNewMovieFromURL ("file://" + qtf.getPath());
- } catch (QTException e) {
- if (e.errorCode() != Errors.userCanceledErr)
- e.printStackTrace();
- }
- }
- });
- quitMenuItem.addActionListener (new ActionListener () {
- public void actionPerformed(ActionEvent event) {
- // closes down QT and quits
- PlayMovie.goAway();
- }
- });
- presentMovieMenuItem.addActionListener (new ActionListener () {
- public void actionPerformed(ActionEvent event) {
- try {
- if (myPlayMovie.getPlayer() == null) return;
-
- // present in full screen mode
- // use the current screen resolution and current movie
- FullScreenWindow w = new FullScreenWindow(new FullScreen(), myPlayMovie);
- MoviePlayer mp = new MoviePlayer (myPlayMovie.getMovie());
- QTCanvas c = new QTCanvas (QTCanvas.kPerformanceResize, 0.5F, 0.5F);
- w.add (c);
- w.setBackground (Color.black);
-
- //remove the movie from its current QTCanvas
- myPlayMovie.getCanvas().removeClient();
- //put it into the new canvas of the FullScreenWindow
- //we restore this in the HideFSWindow's action
- c.setClient (mp, false);
-
- // show FSWindow and setup hide - it is invoke through a mousePressed action
- // so we set this as a listener for both the window and the canvas
- w.show();
- HideFSWindow hw = new HideFSWindow (w, myPlayMovie, c);
- w.addMouseListener (hw);
- c.addMouseListener (hw);
-
- // start the movie playing
- mp.setRate (1);
- } catch (QTException err) {
- err.printStackTrace();
- }
- }
- });
- }
-
- static class HideFSWindow extends MouseAdapter {
- HideFSWindow (FullScreenWindow w, PlayMovie pm, QTCanvas c) {
- this.w = w;
- this.pm = pm;
- this.c = c;
- }
-
- private FullScreenWindow w;
- private PlayMovie pm;
- private QTCanvas c;
-
- public void mousePressed (MouseEvent me) {
- try {
- // this will stop the movie and reset it back to the previous window
- c.removeClient();
- pm.getCanvas().setClient (pm.getPlayer(), false);
- } catch (QTException e) {
- e.printStackTrace();
- } finally {
- w.hide();
- }
- }
- }
- }
-